package se.joakimback.decorator.view;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferedImage;

import se.joakimback.decorator.renderer.ProgressListener;
import se.joakimback.decorator.renderer.Renderer;

public class ResultView extends Component implements ProgressListener {
	/**
	 * 
	 */
	private static final long serialVersionUID = 4888531380549984981L;
	private BufferedImage mPreview = null;
	
	public ResultView() {
		this.setPreferredSize(new Dimension(420, 380));
		
		Renderer.getSingleton().addProgressListener(this);
	}
	
	public void paint(Graphics g) {
		if (mPreview == null) {
			return;
		}
		
		int x = (this.getWidth() - mPreview.getWidth()) / 2;
		int y = (this.getHeight() - mPreview.getHeight()) / 2;
		
		g.setColor(Color.GRAY);
		g.fillRect(0, 0, getWidth(), getHeight());
		g.drawImage(mPreview, x, y, null);
	}

	public void done(BufferedImage result) {
		mPreview = result;
		
		repaint();
	}

	public void preview(BufferedImage preview) {
		mPreview = preview;
		
		repaint();
	}
	
	public void start(int totalItems) {
		/* IGNORE */
	}

	public void update(float progress) {
		/* IGNORE */
	}
}
